package org.aeon.client.view;

import org.aeon.client.context.GlobalContext;
import org.aeon.client.view.components.LoginPanel;
import org.aeon.client.view.components.RegisterPanel;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.MatteBorder;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * @author: MissingAeon
 * @date: 2024/2/21 16:13
 * @description:
 */
public class AccountUI extends JFrame {
    public AccountUI() {
        init();
        // 请求焦点
        this.requestFocusInWindow();
    }

    public static JPanel logPanel() {
        final JPanel panel = new JPanel();
        JLabel label = new JLabel("畅聊");
        label.setFont(new Font("隶书", Font.BOLD, 120));
        // 设置标签水平居中对齐
        label.setHorizontalAlignment(SwingConstants.CENTER);
        // 设置标签垂直居中对齐
        label.setVerticalAlignment(SwingConstants.CENTER);
        // 设置标签前景色为半透明黑色
        label.setForeground(new Color(148, 143, 143, 47));
        // 创建一个空的边框，用于将组件下移
        Border emptyBorder = BorderFactory.createEmptyBorder(120, 0, 0, 0);
        label.setBorder(emptyBorder);
        panel.add(label);
        final MatteBorder border = BorderFactory.createMatteBorder(0, 1, 0, 1, new Color(75, 75, 75, 47));
        panel.setBorder(border);
        return panel;
    }

    private void init() {
        this.setTitle("登陆");
        this.setSize(760, 480);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.setResizable(false);
        // 居中
        this.setLocationRelativeTo(null);

        final JPanel panel = new JPanel();
        final CardLayout layout = new CardLayout();
        panel.setLayout(layout);

        final LoginPanel loginPanel = new LoginPanel(panel);
        final RegisterPanel registerPanel = new RegisterPanel(panel);

        panel.add("LP", loginPanel);
        panel.add("RP", registerPanel);

        this.getContentPane().add(panel);

        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                GlobalContext.getContext().shutdownGracefully();
            }
        });
    }
}
